import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { SystemConfig } from '../model/system-config';
import { Enum } from '../model/enum';

@Injectable({
  providedIn: 'root'
})
export class SystemConfigService {

  constructor(
    private http: HttpClient
  ) { }

  getConfigs(): Observable<SystemConfig[]> {
    return this.http.get<SystemConfig[]>('/system/configs');
  }

  getTypeOptions(): Observable<Enum[]> {
    return this.http.get<Enum[]>('/system/configs/types');
  }

  getValueOptions(attributeKey?: string): Observable<Enum[]> {
    return this.http.get<Enum[]>(`/system/configs/options?attributeKey=${attributeKey}`);
  }

  update(data: SystemConfig): Observable<void> {
    return this.http.put<void>('/system/configs', data);
  }

  updateWechatMenu(): Observable<void> {
    return this.http.post<void>('/wechat/menus', null);
  }
}
